<!-- 编辑简介 -->
<template>
	<view class="profile">
		<view class="profileContent">
			<textarea
				v-model="profile"
				:placeholder="profile?profile:'请输入简介'" />
		</view>
		<view class="btn" @click="edit_profile">保存</view>
	</view>
</template>

<script>
	// 引入封装的请求
	import request from '@/utils/request.js'
export default {
	data() {
		return {
			// 用户信息
			userInfo:{},
			// 当前输入的用户简介
			profile:null
		};
	},
	methods:{
		edit_profile(){
			let that = this
			if(!that.profile){
				uni.showToast({
					title:'请输入简介'
				})
				return flase
			}
			request.post({
				url:'Mini/circle/flea/upUserIntro',
				data:{
					user_intro:that.profile
				}
			}).then(res=>{
				console.log(res)
				uni.showToast({
					title:res.msg
				})
				if(res.code==200){
					let user = JSON.parse(JSON.stringify(that.userInfo))
					user.userInfo.user_intro = that.profile
					uni.setStorageSync('userInfo',user)
					uni.navigateBack()
				}
			})
		},
		// 获取用户简介
		get_user_info(){
			let that = this
			request.get('Mini/circle/flea/getUserIntro').then(res=>{
				if(res.code==200){
					that.profile = res.data.user_intro
				}
			})
		}
	},
	onShow() {
		let that = this
		uni.getStorage({
			key:'userInfo',
			success:function(res){
				that.userInfo = res.data
			},
			fail:function(res){
				uni.navigateTo({
					url: '/login/bindinguser/index'
				})
			},
		})
		this.get_user_info()
	}
};
</script>

<style lang="scss">
page {
	background: #fff;
}
.profile {
	width: 100%;
	padding: 30rpx;

	.profileContent {
		width: 100%;
		height: 500rpx;
		textarea {
			width: 100%;
			height: 300rpx;
		}
	}

	.btn {
		width: 100%;
		height: 90rpx;
		background: linear-gradient(3deg, #fc9e00 0%, #fbb10d 76%);
		border-radius: 45rpx;
		font-size: 36rpx;
		font-family: Hiragino Sans GB;
		color: #fefefe;
		line-height: 90rpx;
		text-align: center;
	}
}
</style>
